package com.project.controller;

import com.project.bean.ClassBean;
import com.project.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;

@RestController
@RequestMapping("class")
public class ClassController {

    @Autowired
    private ClassService service;

    @RequestMapping("findAll")
    public List<ClassBean> findAll() {
        return service.findAll();
    }

    @RequestMapping("add")
    private String addClass(String name, String teacher, LocalDate day) {
        ClassBean classBean = new ClassBean(name, teacher, day);
        service.add(classBean);
        return "OK";
    }

    @RequestMapping("del")
    public String delClass(int id) {
        if (service.del(id)) {
            return "OK";
        }
        return "NO";
    }

    @RequestMapping("byName")
    public Integer byName(String name) {
        return service.findByName(name).getId();
    }
}
